Skip to content

Conversation

@mdelapenya
Copy link
Member

What does this PR do?

According to the log stream specification, the last 4 bytes of the header indicate the length of the log frame. There is an issue when a log message is exactly 10 character long, the header ends with \00\00\00\10. The current implementation uses ReadLine so it doesn't correctly read the header which results in the header being output. This is what the it looks like with the new test:

Error:      	Not equal: 
				expected: "abcdefghi\nfoo"
				actual  : "\x01\x00\x00\x00\x00\x00\x00\ni\nfoo"
				
				Diff:
				--- Expected
				+++ Actual
				@@ -1,2 +1,3 @@
				-abcdefghi
				+�������
				+i
					foo
Test:       	TestContainerLogsShouldBeWithoutStreamHeader

Why is it important?

Related issues

@mdelapenya mdelapenya added the bug Something isn't working label Jul 4, 2025
@mdelapenya mdelapenya self-assigned this Jul 4, 2025

This comment was marked as outdated.

@mdelapenya mdelapenya requested a review from Copilot July 4, 2025 04:43

This comment was marked as outdated.

@mdelapenya mdelapenya requested a review from Copilot July 4, 2025 04:58

This comment was marked as outdated.

@mdelapenya mdelapenya requested a review from Copilot July 4, 2025 05:11

This comment was marked as outdated.

@mdelapenya mdelapenya requested a review from Copilot July 4, 2025 05:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates log handling to comply with the Docker log stream specification by stripping the 8-byte headers for multiplexed stdout/stderr streams and adds tests to verify correct behavior in both TTY and non-TTY modes.

  • Added TTY detection in Logs and a new parseMultiplexedLogs function to strip stream headers
  • Introduced comprehensive tests in container.logs_test.go for header stripping, stderr handling, error logging, and TTY mode
  • Removed the old ReadLine-based trimming logic and replaced it with io.ReadFull/io.CopyN frame parsing

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
container/container.logs.go Detect TTY, route logs through a new binary-frame parser
container/container.logs_test.go New tests verifying header stripping, stderr, errors, and TTY
Comments suppressed due to low confidence (1)

container/container.logs.go:23

  • Inside the container package you should refer to LogsOptions without qualifying it with container. Change container.LogsOptions to LogsOptions for proper compilation.
	options := container.LogsOptions{

@mdelapenya mdelapenya merged commit 3923e95 into docker:main Jul 4, 2025
11 checks passed
@mdelapenya mdelapenya deleted the strip-logs branch July 4, 2025 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant